package com.pubinfo.passbook.common.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.pubinfo.passbook.common.model.bo.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * null
 *
 * @TableName t_subsidiary_private_key
 */
@TableName(value = "t_subsidiary_private_key")
@Data
@NoArgsConstructor
@ApiModel(value = "TSubsidiaryPrivateKey", description = "私钥实体")
public class TSubsidiaryPrivateKey implements Serializable {
  /**
   *
   */
  @TableId(type = IdType.ASSIGN_UUID)
  private String id;
  
  /**
   * 私钥
   */
  @ApiModelProperty(value = "私钥")
  private String privateKey;
  
  /**
   * 密码
   */
  @ApiModelProperty(value = "密码")
  private String password;
  
  /**
   * 是否启用 0 不启用 1启用
   */
  @ApiModelProperty(value = "是否启用 0 不启用 1启用")
  private Integer type;
  
  /**
   * 分公司表id
   */
  @ApiModelProperty(value = "分公司表id")
  private String subId;
  
  @TableField(exist = false)
  private static final long serialVersionUID = 1L;
  
  public TSubsidiaryPrivateKey(Excel export) {
    BeanUtils.copyProperties(export, this);
    this.type = 1;
    this.subId = export.getNsrsbh();
  }
  
  
  public static List<TSubsidiaryPrivateKey> toList(List<Excel> excelList, List<String> passwords) {
    List<TSubsidiaryPrivateKey> list = new ArrayList<>();
    if (excelList != null) {
      excelList.stream().forEach(interfaceExport -> {
        if (StringUtils.isNotBlank(interfaceExport.getPrivateKey())) {
          if (!passwords.contains(interfaceExport.getPassword())) {
            TSubsidiaryPrivateKey privateKey = new TSubsidiaryPrivateKey(interfaceExport);
            list.add(privateKey);
          }
        }
        
      });
    }
    return list;
  }
}